<template>
	<view class="my-search-container" :style="{'background-color': bgcolor}">
		<!-- 使用 view 组件模拟 input 输入框的样式 -->
		<uni-icons type="refresh" size="45" :color="iconColor" style="padding-right: 15rpx;" @click="refreshHandler"
			v-if="refresh">
		</uni-icons>
		<view class="my-search-box" :style="{'background-color': search_box_bgcolor,'border-radius': radius + 'rpx','color':color,
			'width':width}" @click="searchBoxHandler">
			<uni-icons type="search" size="17"></uni-icons>
			<!-- <text class="placeholder">搜索</text> -->
		</view>
		<view style="padding-left: 15rpx;" v-if="camera||sift">
			<iconfont :name="'camera'" size="45" :color="iconColor" :bold="true" v-if="camera" @click="cameraHandler">
			</iconfont>
			<iconfont :name="'sift'" size="45" :color="iconColor" v-if="sift" @click="siftHandler">
			</iconfont>
		</view>

	</view>
</template>

<script>
	export default {
		name: "my-search",
		props: {
			// 背景颜色
			bgcolor: {
				type: String,
				default: '#fff'
			},
			// 圆角尺寸
			radius: {
				type: Number,
				// 单位是 rpx
				default: 30
			},
			width: {
				default: '100%'
			},
			search_box_bgcolor: {
				type: String,
				default: '#e5e6eb'
			},
			color: {
				type: String,
				default: '#000'
			},
			camera: {
				type: Boolean,
				default: false
			},
			sift: {
				type: Boolean,
				default: false
			},
			refresh: {
				type: Boolean,
				default: false
			},
			iconColor: {
				default: '#10aeff'
			}
		},
		data() {
			return {

			};
		},
		methods: {
			// 点击了模拟的 input 输入框
			searchBoxHandler() {
				// 触发外界通过 @search 绑定的 click 事件处理函数
				this.$emit('search')
			},
			cameraHandler() {
				this.$emit('camera')
			},
			siftHandler() {
				this.$emit('sift')
			},
			refreshHandler() {
				this.$emit('refresh')
			}
		}
	}
</script>

<style lang="scss">
	.my-search-container {
		// 移除背景颜色，改由 props 属性控制
		height: 50px;
		padding: 5px 10px;
		display: flex;
		align-items: center;
		justify-content: center;

		.my-search-box {
			height: 36px;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;

			.placeholder {
				font-size: 14px;
				margin-left: 10rpx;
			}
		}
	}
</style>